package com.sttk.fastMark.camera.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

/**
 * 九宫格参考线视图
 */
public class ReferenceLineView extends View {
    
    private Paint linePaint;
    private int lineColor = Color.WHITE;
    private float lineWidth = 2f;
    
    public ReferenceLineView(Context context) {
        super(context);
        init();
    }
    
    public ReferenceLineView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }
    
    public ReferenceLineView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }
    
    private void init() {
        linePaint = new Paint();
        linePaint.setColor(lineColor);
        linePaint.setStrokeWidth(lineWidth);
        linePaint.setAntiAlias(true);
        linePaint.setAlpha(128); // 50% 透明度
    }
    
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        
        int width = getWidth();
        int height = getHeight();
        
        // 绘制九宫格参考线
        // 水平线
        float horizontalStep = height / 3f;
        for (int i = 1; i < 3; i++) {
            float y = i * horizontalStep;
            canvas.drawLine(0, y, width, y, linePaint);
        }
        
        // 垂直线
        float verticalStep = width / 3f;
        for (int i = 1; i < 3; i++) {
            float x = i * verticalStep;
            canvas.drawLine(x, 0, x, height, linePaint);
        }
    }
    
    /**
     * 设置参考线颜色
     */
    public void setLineColor(int color) {
        this.lineColor = color;
        linePaint.setColor(color);
        invalidate();
    }
    
    /**
     * 设置参考线宽度
     */
    public void setLineWidth(float width) {
        this.lineWidth = width;
        linePaint.setStrokeWidth(width);
        invalidate();
    }
}